﻿using System.Data.SqlServerCe;
using System.IO;

namespace nToDo
{
    public static class DataManagement
    {
        static string connectionString = string.Empty;
        static DataManagement()
        {
            string applicationDbPath = Path.Combine(Properties.Settings.Default.DbPath, "nTodo.sdf");
            if (!File.Exists(applicationDbPath))
            {
                throw new FileNotFoundException("Database file not found", "ntodo.sdf");
            }
            DataAccess.GetInstance().CloseConnection();
            connectionString = string.Format(Properties.Settings.Default.Connection, applicationDbPath);
        }
        public static void Compact()
        {
            using (SqlCeEngine engine = new SqlCeEngine(connectionString))
            {
                engine.Verify(VerifyOption.Default);
                engine.Compact(connectionString);
                engine.Shrink();
            }
        }
    }
}
